package com.zhentao.websocket.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.time.LocalDateTime;

@Document(collection = "chat_messages")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ChatMessage {
    @Id
    private String id;

    @Indexed
    @Field("fromId")
    private Integer fromId;

    @Indexed
    @Field("toId")
    private Integer toId;



    @Indexed
    private String fromName;
    
    @Indexed
    private String toName;


    private String message;
    
    @Indexed
    private LocalDateTime timestamp;
    
    @Indexed
    private String conversationId; // 会话ID，由fromName和toName生成
    
    private String messageType = "text"; // text, image, voice, video, file

    // 图片消息相关字段
    private String imageUrl; // 图片URL（当messageType为image时使用）
    private String thumbnailUrl; // 缩略图URL（可选）
    private Long fileSize; // 文件大小（字节）
    private String originalFilename; // 原始文件名

    // 视频消息相关字段
    private String videoUrl; // 视频URL（当messageType为video时使用）
    private String videoCoverUrl; // 视频封面图URL
    private Long videoDuration; // 视频时长（秒）
    private Integer videoWidth; // 视频宽度
    private Integer videoHeight; // 视频高度

    private boolean isRead = false; // 是否已读

    private boolean isDeleted = false; // 是否已删除


    private String targetAvatar;
    private String targetName;

    // 头像信息字段
    @Field("fromAvatar")
    private String fromAvatar; // 发送方头像URL
    @Field("toAvatar")
    private String toAvatar; // 接收方头像URL
/*
    public ChatMessage() {
    }

    public ChatMessage(String fromName, String toName, String message) {
        this.fromName = fromName;
        this.toName = toName;
        this.message = message;
        this.timestamp = LocalDateTime.now();
    }

    public ChatMessage(String fromName, String toName, String message, String messageType) {
        this.fromName = fromName;
        this.toName = toName;
        this.message = message;
        this.messageType = messageType;
        this.timestamp = LocalDateTime.now();
    }
*/
    // 图片消息专用构造函数
    public ChatMessage(String fromName, String toName, String imageUrl, String originalFilename, Long fileSize) {
        this.fromName = fromName;
        this.toName = toName;
        this.message = imageUrl; // 图片消息的message字段存储图片URL
        this.messageType = "image";
        this.imageUrl = imageUrl;
        this.originalFilename = originalFilename;
        this.fileSize = fileSize;
        this.timestamp = LocalDateTime.now();
    }

    // 视频消息专用构造函数
    public ChatMessage(String fromName, String toName, String videoUrl, String originalFilename, Long fileSize, Long videoDuration) {
        this.fromName = fromName;
        this.toName = toName;
        this.message = videoUrl; // 视频消息的message字段存储视频URL
        this.messageType = "video";
        this.videoUrl = videoUrl;
        this.originalFilename = originalFilename;
        this.fileSize = fileSize;
        this.videoDuration = videoDuration;
        this.timestamp = LocalDateTime.now();
    }


}
